﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Enter.DataProxy.Cache.Configuration
{
    internal class CacheTypeSettings
    {
        private CacheType _cachetype = CacheType.velocitycache;

        public CacheType Cachetype
        {
            get { return _cachetype; }
            set { _cachetype = value; }
        }

    }


    internal enum CacheType
    {
        memcache = 1,
        velocitycache = 2,
        nosql = 3,
        webcache=4,
    }

    [Serializable]
    [XmlRoot(ElementName = "CacheSetting", DataType = "string", IsNullable = true)]
    internal class CacheSetting
    {
        private List<CacheServer> _CacheServers = null;

        /// <summary>
        /// 缓存服务器列表
        /// </summary>
        public List<CacheServer> CacheServers
        {
            get { return _CacheServers; }
            set { _CacheServers = value; }
        }

        private bool _enableCaching = false;



        /// <summary>
        /// 是否使用缓存
        /// </summary>
        public bool EnableCaching
        {
            get { return _enableCaching; }
            set { _enableCaching = value; }
        }

        private bool _enableLog = false;

        /// <summary>
        /// 是否使用日志
        /// </summary>
        public bool EnableLog
        {
            get { return _enableLog; }
            set { _enableLog = value; }
        }


        private int _CachingTime = 10;

        /// <summary>
        /// 缓存默认时间 秒
        /// </summary>
        public int CachingTime
        {
            get { return _CachingTime; }
            set { _CachingTime = value; }
        }


        private string _CacheName = string.Empty;

        /// <summary>
        /// 缓存名称
        /// </summary>
        public string CacheName
        {
            get { return _CacheName; }
            set { _CacheName = value; }
        }

    }

    [Serializable]
    [XmlRoot(ElementName = "CacheServer", DataType = "string", IsNullable = true)]
    internal class CacheServer
    {
        private string _hostName = string.Empty;

        /// <summary>
        /// 服务器名称或IP
        /// </summary>
        [XmlAttribute("HostName")]
        public string HostName
        {
            get { return _hostName; }
            set { _hostName = value; }
        }

        private int _cachePort = 22233;

        /// <summary>
        /// 服务端口
        /// </summary>
        [XmlAttribute("CachePort")]
        public int CachePort
        {
            get { return _cachePort; }
            set { _cachePort = value; }
        }

    }

    [Serializable]
    internal class CacheErrSet
    {
        private bool _EnableCheck = false;

        /// <summary>
        /// 是否使用异常缓存还原检测
        /// </summary>
        public bool EnableCheck
        {
            get { return _EnableCheck; }
            set { _EnableCheck = value; }
        }

        private int _IntervalTime = 10;

        /// <summary>
        /// 检测间隔时间
        /// </summary>
        public int IntervalTime
        {
            get { return _IntervalTime; }
            set { _IntervalTime = value; }
        }

        private int _Maximum = 0;

        /// <summary>
        /// 检测最大次数 0永远检测
        /// </summary>
        public int Maximum
        {
            get { return _Maximum; }
            set { _Maximum = value; }
        }

    }
}
